/**
 * Created by Administrator on 2015/11/9.
 */

//F1快速发布报价
$(function(){
    $(".publish_price .publish").on("click",function(){
        var content = $.trim($(".publish_price .content").val());
        var business_name = $.trim($(".publish_price .business_name").val());
        var contacts = $.trim($(".publish_price .contacts").val());
        var mobile = $.trim($(".publish_price .mobile").val());
        var regBox = {
            regEmail:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            regName : /^[a-zA-Z0-9_-]{3,16}$/,//验证数字字母下划线
            regCh : /^[\u4e00-\u9fa5]{0,}$/,//验证汉子
            regMobile : /^0?1[3|4|5|7|8][0-9]\d{8}$/,//手机
            regTel : /^0[\d]{2,3}-[\d]{7,8}$/
        }
        if(!content || content==''){
            alert("请填写报价内容！");return false;
        }

        if(!business_name || business_name==''){
            alert("请填写报价公司名称！");return false;
        }

        if(!contacts || contacts==''){
            alert("请填写报价联系人！");return false;
        }
        var mcontacts = regBox.regCh.test(contacts);
        if(!mcontacts){
            alert("联系人有误！");return false;
        }

        if(!mobile || mobile==''){
            alert("请填写报价手机号码！");return false;
        }

        var mmobile = regBox.regMobile.test(mobile);
        if(!mmobile){
            alert("手机号码有误！");return false;
        }

        $.ajax({
            url:'/json/PublishPrice',
            data:{
                content:content,
                business_name:business_name,
                contacts:contacts,
                mobile:mobile,
            },
            type:'POST',
            success:function(data){
                var code = data.code;
                var msg = data.msg;
                if(code==8){
                    alert(msg);
                    $(".publish_price .content").val("");
                    $(".publish_price .business_name").val("");
                    $(".publish_price .contacts").val("");
                    $(".publish_price .mobile").val("");
                }else{
                    alert(msg);
                }
            },
            dataType:'json'
        });
    });
});

//F2快速发布求购
$(function(){
    $(".publish_inquire .publish").on("click",function(){
        var content = $.trim($(".publish_inquire .content").val());
        var business_name = $.trim($(".publish_inquire .business_name").val());
        var contacts = $.trim($(".publish_inquire .contacts").val());
        var mobile = $.trim($(".publish_inquire .mobile").val());
        var regBox = {
            regEmail:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            regName : /^[a-zA-Z0-9_-]{3,16}$/,//验证数字字母下划线
            regCh : /^[\u4e00-\u9fa5]{0,}$/,//验证汉子
            regMobile : /^0?1[3|4|5|7|8][0-9]\d{8}$/,//手机
            regTel : /^0[\d]{2,3}-[\d]{7,8}$/
        }
        if(!content || content==''){
            alert("请填写求购内容！");return false;
        }

        if(!business_name || business_name==''){
            alert("请填写求购公司名称！");return false;
        }

        if(!contacts || contacts==''){
            alert("请填写求购联系人！");return false;
        }
        var mcontacts = regBox.regCh.test(contacts);
        if(!mcontacts){
            alert("联系人有误！");return false;
        }

        if(!mobile || mobile==''){
            alert("请填写求购手机号码！");return false;
        }

        var mmobile = regBox.regMobile.test(mobile);
        if(!mmobile){
            alert("手机号码有误！");return false;
        }

        $.ajax({
            url:'/json/PublishInquire',
            data:{
                content:content,
                business_name:business_name,
                contacts:contacts,
                mobile:mobile,
            },
            type:'POST',
            success:function(data){
                var code = data.code;
                var msg = data.msg;
                if(code==8){
                    alert(msg);
                    $(".publish_inquire .content").val("");
                    $(".publish_inquire .business_name").val("");
                    $(".publish_inquire .contacts").val("");
                    $(".publish_inquire .mobile").val("");
                }else{
                    alert(msg);
                }
            },
            dataType:'json'
        });
    });
});